﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion


#region Usings

using Microsoft.Practices.Unity;
using ScrumTable.UI.ViewModel.Tools;

#endregion

namespace ScrumTable.UI.View.WinTouch.UserControls.Tool
{
    /// <summary>
    /// Interaction logic for TeamMemberSelector.xaml
    /// </summary>
    public partial class UndoRedoHistory  
    {

        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------
    
        /// <summary>
        /// Gets or sets the model.
        /// </summary>
        /// <value>The model.</value>
        [Dependency]
        public UndoRedoHistoryViewModel  Model
        {
            set
            {
                ViewModel = value;
            }
            get
            {
                return (UndoRedoHistoryViewModel)ViewModel;
            }
        } 

        #endregion

        #region Constructors / Destructor
        //--------------------------------------------------------------------
        // Constructors / Destructor
        //--------------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="TeamMemberSelector"/> class.
        /// </summary>
        public UndoRedoHistory()
        {
            InitializeComponent();
        }
        #endregion

        #region events

        private void OnUndoListClick(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            if (ListUndo.SelectedItem != null)
            {
                int pos = ListUndo.Items.IndexOf(ListUndo.SelectedItem);
                for (int i = 0; i <= pos; i++)
                {
                    Model.ScrumData.DataContext.UndoManager.Undo();
                }
            }
        }

        private void OnRedoListClick(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            if( ListRedo.SelectedItem != null)
            {
                int pos = ListRedo.Items.IndexOf(ListRedo.SelectedItem);
                for (int i = 0; i <= pos; i++)
                {
                    Model.ScrumData.DataContext.UndoManager.Redo();
                }
            }
        }
        #endregion

        private void OnUndoClick(object sender, System.Windows.RoutedEventArgs e)
        {
            Model.ScrumData.DataContext.UndoManager.Undo();
        }

        private void OnRedoClick(object sender, System.Windows.RoutedEventArgs e)
        {
            Model.ScrumData.DataContext.UndoManager.Redo();
        }

        private void DeleteUndoStack(object sender, System.Windows.RoutedEventArgs e)
        {
            Model.ScrumData.DataContext.UndoManager.DiscardAllEdits();
        }
    }
}
